package ventanas;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import controladores.ControladorBusquedaObrasSociales;
import javax.swing.DefaultListModel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JList;
import negocio.ObraSocial;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class VentanaBusquedaObrasSociales extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private final JTextField txtBuscar = new JTextField();
	private final JButton btnBuscarOS = new JButton("Buscar Obra Social");
	private final JList<ObraSocial> lista = new JList<ObraSocial>();
	private final JButton btnC = new JButton("C");
	private final JButton btnNuevaOS = new JButton("Nueva Obra Social");
	private ControladorBusquedaObrasSociales controlador;
	private final JLabel lblObrasSociales = new JLabel("Obras Sociales");
	private final JScrollPane scrollPane = new JScrollPane();
	
	public VentanaBusquedaObrasSociales() {
		setTitle("B\u00FAsqueda de Obra Social");
		controlador = new ControladorBusquedaObrasSociales(this);
		initGUI();
		agregarListeners();
	}
	
	private void initGUI() {
		txtBuscar.setColumns(10);
		setBounds(100, 100, 421, 342);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("max(175dlu;default):grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(95dlu;default)"),},
			new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(96dlu;default):grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(43dlu;default)"),}));
		contentPane.add(lblObrasSociales, "1, 1, center, default");
		contentPane.add(txtBuscar, "1, 3, fill, center");
		contentPane.add(btnBuscarOS, "3, 3");
		contentPane.add(btnC, "3, 5");
		
		contentPane.add(scrollPane, "1, 7, fill, fill");
		scrollPane.setViewportView(lista);
		lista.setModel(new DefaultListModel<ObraSocial>());
		contentPane.add(btnNuevaOS, "3, 7");
		this.setVisible(true);
		this.setLocationRelativeTo(null);
		this.pack();
	}

	private void agregarListeners(){
		btnBuscarOS.addActionListener(controlador);
		btnC.addActionListener(controlador);
		btnNuevaOS.addActionListener(controlador);
		lista.addMouseListener(controlador);
	}

	
	//getters y setters
	public JTextField getTxtBuscar() {
		return txtBuscar;
	}

	public JButton getBtnBuscarOS() {
		return btnBuscarOS;
	}

	public JList<ObraSocial> getLista() {
		return lista;
	}

	public JButton getBtnC() {
		return btnC;
	}

	public JButton getBtnNuevaOS() {
		return btnNuevaOS;
	}
}
